package cn.lsh.reducer;

import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;
import java.util.StringTokenizer;

public class HotComment3Reducer extends Reducer<Text, Text, Text, Text> {

	@Override
	protected void reduce(Text key, Iterable<Text> values, Context context) throws IOException, InterruptedException {
		//输入数据样例：
		//7103300_0.03846	风月
		String id = "";
		StringBuffer sb = new StringBuffer();
		for (Text value : values) {
			StringTokenizer st = new StringTokenizer(key.toString(), "_");
			id = st.nextToken();
			sb.append(value.toString()).append(":").append(st.nextToken()).append("\t");
		}
		context.write(new Text(id), new Text(sb.toString()));
	}
}
